package com.czmc.wifivideo.net.udp

import com.czmc.wifivideo.net.Sender
import java.net.DatagramPacket
import java.net.DatagramSocket
import java.net.InetAddress

/**
 * @author czmc
 * @version 1.0
 * @email: chenzhiming@dkhs.com
 * @description TODO
 * @date 12/5/2018
 */

class UDPSender(val ip:String=Constant.HOST,val port:Int=Constant.PORT_SEND): Sender {

    override fun send(message:String) {
        val bytes = message.toByteArray()
        val socket = DatagramSocket()
        socket.send(DatagramPacket(bytes,0,bytes.size, InetAddress.getByName(ip),port))
        socket.disconnect()
    }

}